package com.demo.component.configuration;

import com.demo.component.bean.Properties;
import freemarker.template.Configuration;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModelException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class FreemarkerConfig {

	protected static final Logger log = LoggerFactory.getLogger(FreemarkerConfig.class);

	@Autowired
	private Configuration configuration;
	@Autowired
	private Properties properties;
	@PostConstruct
	public void setSharedVariable() throws TemplateModelException {
		// 自定义方法
		// 全局变量
		try {
//			configuration.setSharedVariable("baseRes", properties.getBaseRes());
//			configuration.setSharedVariable("basePath", properties.getBasePath());
			configuration.setSharedVariable("baseRes", "");
			configuration.setSharedVariable("basePath", "");

		} catch (TemplateException e) {
			e.printStackTrace();
			log.error("读取：application.properties参数失败！");
		}
	}

}
